/**
 * @descript 公司运营报表
 */

var _select_target = 999,
	_select_cols = [],
	type, date;
$(function() {
	//修改表格高度
	var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$('#tableList').attr({
		'data-height': h - 96
	});
	type = getURLParam('type');
	date = getURLParam('date');
	getDataForTable(_select_target);
});
/**
 * 获取表格数据
 * @param {Object} code 获取的数据类型
 */
function getDataForTable(code) {
		getDataInterFace({
			code: 4,
			type: type,
			date: date
		}, setDataToTale);
	}
	/**
	 * 绑定数据到表格上
	 */

function setDataToTale(data) {
		//data = data ? $.parseJSON(data) : {};
		data = data || {
			users: []
		};
		createTable();
		$('#tableList').bootstrapTable({
			data: data.users
		});
	}
	/**
	 * 创建表格
	 */

function createTable() {
		var cols = _COLUMNS_TEXT[_select_target],
			tCols = [];
		_select_cols = [];
		for (var k in cols) {
			if (cols[k].isshow) {
				tCols.push($('<th>').attr({
					'data-field': k,
					'data-halign': cols[k]['halign'] || 'center',
					'data-align': cols[k]['align'] || 'center',
					'data-formatter': cols[k]['formatter'] || ''
				}).html(cols[k]['text']));
				_select_cols.push(k);
			}
		}
		$('#tableList thead tr').append(tCols);
	}
	/**
	 * 获取地址栏中的参数值
	 * @param {Object} p 参数名称
	 */

function getURLParam(p) {
	var href = window.location.href,
		s = window.location.search.substr(1),
		reg = new RegExp(p + "=([^&]*)"),
		sp = '?',
		ps = s.match(reg);

	if (ps != null) { // 说明该参数存在,替换成新值
		return ps[1];
	} else {
		return ps;
	}
}